#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    bool isHasCircle(unordered_map<int, unordered_set<int>> &edges) {
        unordered_set<int> black;
        unordered_set<int> grey;
        function<bool(int)> dfs = [&](int u)->bool
            {
                if (black.count(u)) return false;
                grey.emplace(u);
                for (auto &v : edges[u]) {
                    if (black.count(v)) continue;
                    if (grey.count(v)) return true;
                    if (dfs(v)) return true;
                }
                grey.erase(u);
                black.emplace(u);
                return false;
            };
        for (auto &x : edges) {
            if (dfs(x.first)) return true;
        }
        return false;
    }
};

int main() {
    unordered_map<int, unordered_set<int>> edges;
    string readed;
    int N, E;
    cin >> N >> E;
    while (E--) {
        int u, v;
        cin >> u >> v;
        edges[u].emplace(v);
    }
    cout << (Solution().isHasCircle(edges) ? 0 : 1) << endl;
    //system("pause");
    return 0;
}
